/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package erpretailx.Modul;


import java.io.File;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

/**
 *
 * @author Al Quthsi
 */
public class ModulClassLoader extends URLClassLoader{


    public ModulClassLoader(ClassLoader parent, File modLib) throws MalformedURLException{
        super(new URL[]{modLib.toURI().toURL()}, parent);
    }

    public void addModul(File ModulDir) throws MalformedURLException{
        File libDir = new File(ModulDir, "lib");

        File jars[] = libDir.listFiles(new FilenameFilter() {
            //filter list file to accept jar and zip file
            public boolean accept(File dir, String name) {
                boolean accept = false;
                String smallname = name.toLowerCase();
                if(smallname.endsWith(".jar")){
                    accept = true;
                }else if(smallname.endsWith(".zip")){
                    accept = true;
                }
                else{
                    accept = false;
                }
                return accept;
            }
        });
        //if jars nothing file zip or jar return null
        if(jars == null){
            return;
        }

        
        for(File jar : jars ){
         //for each file jar
            if(jar.isFile()){
                final URL url = jar.toURL();
                addURL(url);
                try{

                }catch(Throwable e){
                    e.printStackTrace();
                }
            }
        }
}
    

}
